<?php


namespace App\Rpc\common\impl;

use App\Common\Res;
use App\Common\StringUtils;
use App\Model\File;
use App\Request\common\FileRequest;
use App\Rpc\common\FileInterface;
use Hyperf\DbConnection\Db;
use Hyperf\Utils\ApplicationContext;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;


class FileImpl implements FileInterface
{
    use StringUtils, Res;

    /**
     * 上传文件信息
     * @param array $params
     * @return array
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function addFilePath(array $params): array
    {
        ApplicationContext::getContainer()->get(FileRequest::class)->validated($params, __FUNCTION__);
        $result = File::updateOrCreate(['name' => $params['name']], [
            'name' => $params['name'],
            'path' => $params['path'],
        ]);
        return $this->Success('上传成功', $result);
    }
}